package com.abaaba.project2.controller;

import com.abaaba.project2.bean.Keyword;
import com.abaaba.project2.bean.bo.AdminKeywordBo;
import com.abaaba.project2.bean.vo.AdminKeywordVo;
import com.abaaba.project2.bean.vo.BaseRespVo;
import com.abaaba.project2.service.AdminKeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Key;

@RestController
@RequestMapping("/admin/keyword")
public class AdminKeywordController {
    @Autowired
    AdminKeywordService adminKeywordService;

    @RequestMapping("/list")
    public BaseRespVo getKeywordList(Integer page, Integer limit, String keyword, String url, String sort, String order) {
        AdminKeywordVo adminKeywordVo = adminKeywordService.getKeywordList(page, limit, keyword, url, sort, order);
        return BaseRespVo.ok(adminKeywordVo);
    }

    @RequestMapping("/delete")
    public BaseRespVo deleteKeyword(@RequestBody Keyword keyword) {
        Integer affectedRows = adminKeywordService.deleteKeyword(keyword);
        return BaseRespVo.ok();
    }

    @RequestMapping("/create")
    public BaseRespVo createKeyword(@RequestBody AdminKeywordBo adminKeywordBo) {
        Keyword keyword = adminKeywordService.createKeyword(adminKeywordBo);
        return BaseRespVo.ok(keyword);
    }

    @RequestMapping("/update")
    public BaseRespVo updateKeyword(@RequestBody Keyword keyword) {
        Keyword keyword1 = adminKeywordService.updateKeyword(keyword);
        return BaseRespVo.ok(keyword1);
    }
}
